<style>
    /*背景层*/
    #popLayer {
        display: none;
        background-color: #B3B3B3;
        position: absolute;
        top: 0px;
        right: 0px;
        bottom: 0px;
        left: 0px;
        z-index: 10;
        -moz-opacity: 0.8;
        opacity:0.80;
        filter: alpha(opacity=80);/* 只支持IE6、7、8、9 */
    }

    /*弹出层*/
    #popBox {
        display: none;
        background-color: #FFFFFF;
        position:absolute;
        z-index: 110;
        width: 90%;
        height:90%;
        top:0;
        right:0;
        left:0;
        bottom:0;
        opacity:1;
        margin:auto;
    }
</style>

<div id="popLayer" ></div>
<div id="popBox"  >
    <span style="padding:10px;background: #787878;float:right;color:white" onclick="closeFrame()" >关闭</span>
<iframe id="popFrame"  style="width:100%;height:100%;border:1px solid #bbb;"  src=""></iframe>
</div>
<div id="app">
    <section class="content-header">
        <h1>
            <small>全部商品列表</small>
        </h1>
    </section>

    <section class="content">
        <div class="row">
            <div class="col-md-12">
                <div class="box">
                    <div class="box-header with-border">


                        <span>
   <input type="checkbox" class="grid-select-all" />&nbsp;
    <div class="btn-group">
        <a class="btn btn-sm btn-default">&nbsp;<span class="hidden-xs">操作</span></a>
        <button type="button" class="btn btn-sm btn-default dropdown-toggle" data-toggle="dropdown">
            <span class="caret"></span>
            <span class="sr-only">Toggle Dropdown</span>
        </button>
        <ul class="dropdown-menu" role="menu">

        </ul>
    </div>
    <a class="btn btn-sm btn-primary grid-refresh" title="刷新"><i class="fa fa-refresh"></i><span class="hidden-xs"> 刷新</span></a>

    <div class="btn-group" style="margin-right: 10px" data-toggle="buttons">
        <label class="btn btn-sm btn-dropbox shaixuan-filter-btn" title="筛选">
            <input type="checkbox"><i class="fa fa-filter"></i><span class="hidden-xs">筛选</span>
        </label>
    </div>
  </span>
</div>

                    <!--   筛选开始   -->
                    <div class="box-header with-border hide" id="filter-box">
                        <form action="/admin/goods/goods" class="form-horizontal" pjax-container method="get">
                            <div class="row">
                                <div class="col-md-12">
                                    <div class="box-body">
                                        <div class="fields-group">
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label"> 商品id</label>
                                                <div class="col-sm-8">
                                                    <div class="input-group input-group-sm">
                                                        <div class="input-group-addon">
                                                            <i class="fa fa-pencil"></i>
                                                        </div>

                                                        <input type="text" class="form-control goods_id" placeholder="商品id" name="goods_id" value="@if(!empty($where['goods_id'])) {{$where['goods_id']}} @endif">
                                                    </div>    </div>
                                            </div>
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label"> 商品名称</label>
                                                <div class="col-sm-8">
                                                    <div class="input-group input-group-sm">
                                                        <div class="input-group-addon">
                                                            <i class="fa fa-pencil"></i>
                                                        </div>

                                                        <input type="text" class="form-control goods_name" placeholder="商品名称" name="goods_name" value="@if(!empty($where['goods_name'])) {{$where['goods_name']}} @endif">
                                                    </div>    </div>
                                            </div>

                                            <div class="form-group">
                                                <label class="col-sm-2 control-label"> 商品状态</label>
                                                <div class="col-sm-8">
                                                    <select class="form-control is_putaway" id="is_putaway" name="is_putaway" style="width: 100%;">
                                                        <option></option>
                                                        <option value="1" >待提交</option>
                                                        <option value="2" >待审核</option>
                                                        <option value="3" >已上架</option>
                                                        <option value="4" >下架</option>
                                                        <option value="5" >驳回</option>
                                                    </select>
                                                </div>
                                            </div>

                                            <div class="form-group">
                                                <label class="col-sm-2 control-label"> 授权品牌</label>
                                                <div class="col-sm-8">
                                                    <select class="form-control brand_id" id="brand_id" name="brand_id" style="width: 100%;">
                                                        <option></option>
                                                        @if($brand)
                                                            @foreach($brand as $k=>$v)
                                                                <option value="{{$k}}">{{$v}}</option>
                                                            @endforeach
                                                        @endif
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label"> 授权渠道</label>
                                                <div class="col-sm-8">
                                                    <select class="form-control cha_id" id="cha_id" name="cha_id" style="width: 100%;">
                                                        <option></option>
                                                        @if($channel)
                                                            @foreach($channel as $k=>$v)
                                                                <option value="{{$k}}">{{$v}}</option>
                                                            @endforeach
                                                        @endif
                                                    </select>
                                                </div>
                                            </div>

                                            <div class="form-group">
                                                <label class="col-sm-2 control-label">创建时间</label>
                                                <div class="col-sm-8" style="width: 390px">
                                                    <div class="input-group input-group-sm">
                                                        <div class="input-group-addon">
                                                            <i class="fa fa-calendar"></i>
                                                        </div>
                                                        <input type="text" class="form-control" id="create_time_start" placeholder="创建时间" name="start_time" value="@if(!empty($where['start_time'])) {{$where['start_time']}} @endif">
                                                        <span class="input-group-addon" style="border-left: 0; border-right: 0;">-</span>
                                                        <input type="text" class="form-control" id="create_time_end" placeholder="创建时间" name="end_time" value="@if(!empty($where['end_time'])) {{$where['end_time']}} @endif">
                                                    </div>
                                                </div>
                                            </div>

                                        </div>
                                    </div>
                                </div>
                            </div>
                            <!-- /.box-body -->

                            <div class="box-footer">
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="col-md-2"></div>
                                        <div class="col-md-8">
                                            <div class="btn-group pull-left">
                                                <button class="btn btn-info submit btn-sm"><i
                                                            class="fa fa-search"></i>&nbsp;&nbsp;搜索</button>
                                            </div>
                                            <div class="btn-group pull-left " style="margin-left: 10px;">
                                                <a href="/admin/goods/goods" class="btn btn-default btn-sm"><i
                                                            class="fa fa-undo"></i>&nbsp;&nbsp;重置</a>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                    <!--筛选结束-->



                    <!-- /.box-header -->
                    <!--数据列表开始   -->
                    <div class="box-body table-responsive no-padding">
                        <table class="table table-hover">
                            <thead >
                            <tr >
                                <th> </th>
                                <th>商品id</th>
                                <th>商品状态</th>
                                <th>商品名称</th>
                                <th>商品价格(元)</th>
                                <th>官方价格(元)</th>
                                <th>创建时间</th>
                                <th>是否已删除</th>
                                <th>列表图片</th>
                                <th>下单缩略图</th>

                                <th>操作</th>
                            </tr>
                            </thead>

                            <tbody>

                            @if (!empty($data['data']))
                                @foreach($data['data'] as $v)
                                    <tr >
                                        <td >
                                            <input type="checkbox" class="grid-row-checkbox" data-id="{{ $v['goods_id']}}" />
                                        </td>
                                        <td >
                                            {{ $v['goods_id'] }}
                                        </td>
                                        <td >
                                            {{$v['goods_status']}}
                                        </td>
                                        <td >
                                            <textarea style="width:100%;height:100%;">{{$v['goods_name']}}</textarea>

                                        </td>

                                        <td >
                                            {{$v['goods_price']}}
                                        </td>
                                        <td >
                                            {{$v['goods_official_price']}}
                                        </td>

                                        <td >
                                            @if($v['create_time'])
                                                {{ date('Y-m-d H:i:s',$v['create_time'])}}

                                            @else
                                                --
                                            @endif

                                        </td>
                                        <td >
                                            @if($v['is_delete']==0)
                                                <button onclick="del(this,{{$v['goods_id']}})" style="color:blue;">否</button>
                                            @else
                                                <button onclick="del(this,{{$v['goods_id']}})" style="color:red;">是</button>
                                            @endif
                                        </td>
                                        <td >
                                        <img src="{{$url}}{{$v['goods_img_list']}}" width="100">
                                        </td>
                                        <td >
                                        <img src="{{$url}}{{$v['goods_order_thumbnail']}}" width="100">
                                        </td>

                                        <td >
                                            <a onclick="popShow(this)" href="javascript:;"  href="/admin/goods/goodsShow?goods_id={{$v['goods_id']}}">
                                                 查看
                                            </a> |
                                            <a  @if(!$v['is_set_GoodsLease']) style="color:red;" @endif   href="/admin/goods/goodsLease?goods_id={{$v['goods_id']}}"    >
                                                租期
                                            </a> |

                                            <a  @if(!$v['is_set_attrType']) style="color:red;" @endif   href="/admin/goods/sku?goods_id={{$v['goods_id']}}"    >
                                                属性
                                            </a> |

                                            <a   @if(!$v['is_set_GoodsImg']) style="color:red;" @endif   href="/admin/goods/goodsAddImg?goods_id={{$v['goods_id']}}"    >
                                                图片
                                            </a> |
                                            <a   @if(!$v['is_set_spec']) style="color:red;" @endif   href="/admin/goods/goodsAttr?goods_id={{$v['goods_id']}}"   >
                                                规格
                                            </a> |
                                            <a   @if(!$v['is_set_GoodsSku']) style="color:red;" @endif   href="/admin/goods/goodsSku?goods_id={{$v['goods_id']}}"   >
                                                SKU
                                            </a>
                                        </td>


                                    </tr>
                                @endforeach
                            @endif
                            </tbody>
                        </table>
                    </div>
                    <!--数据列表结束-->



                    <!-- 分页开始    -->
                    <div class="box-footer clearfix">
                        @if($data['data'])
                        从 <b>{{$data['from']}}</b> 到 <b>{{$data['to']}}</b> ，总共 <b>{{$data['total']}}</b> 条
                        <ul class="pagination pagination-sm no-margin pull-right">
                            <!-- Previous Page Link -->
                            @if($data['page_list'])
                                <li class="page-item @if($data['current_page']==1) disabled @endif ">
                                    @if($data['current_page']>1)
                                        <a class="page-link" data-href="{{$data['page_url']}}&page={{$data['up_page']}}" rel="next">&laquo;</a>
                                    @else
                                        <span class="page-link">&laquo;</span>
                                    @endif</li>
                                @foreach($data['page_list'] as $v)
                                    @if($v=='...')
                                        <li class="page-item disabled"><span class="page-link">{{$v}}</span></li>
                                    @endif
                                    @if($v==$data['current_page'])
                                        <li class="page-item active"><span class="page-link">{{$v}}</span></li>
                                    @elseif($v!='...')
                                        <li class="page-item"><a class="page-link" data-href="{{$data['page_url']}}&page={{$v}}">{{$v}}</a></li>
                                    @endif
                                @endforeach
                                <li class="page-item @if($data['current_page']==$data['last_page']) disabled @endif ">
                                    @if($data['current_page']<$data['last_page'])
                                        <a class="page-link" data-href="{{$data['page_url']}}&page={{$data['next_page']}}" rel="next">&raquo;</a>
                                    @else
                                        <span class="page-link">&raquo;</span>
                                    @endif</li>
                            @endif
                        </ul>

                        <label class="control-label pull-right" style="margin-right: 10px; font-weight: 100;">
                            <small>显示</small>&nbsp;
                            <select class="input-sm grid-per-pager" name="per-page">
                                <option value="{{$data['page_url']}}&per_page=10" >10</option>
                                <option value="{{$data['page_url']}}&per_page=20" selected>20</option>
                                <option value="{{$data['page_url']}}&per_page=30" >30</option>
                                <option value="{{$data['page_url']}}&per_page=50" >50</option>
                                <option value="{{$data['page_url']}}&per_page=100" >100</option>
                            </select>
                            &nbsp;<small>条</small>
                        </label>
                        @else
                            <div style="text-align: center;margin:20px;">未查到数据</div>
                        @endif
                    </div>
                    <!-- 分页结束    -->

                    <!-- /.box-body -->
                </div>
            </div>
        </div>

    </section>
</div>

<script data-exec-on-popstate>



    $(function () {
        $("#is_putaway").val("@if(!empty($where['is_putaway'])){{$where['is_putaway']}}@endif");
        $("#brand_id").val("@if(!empty($where['brand_id'])){{$where['brand_id']}}@endif");
        $("#cha_id").val("@if(!empty($where['cha_id'])){{$where['cha_id']}}@endif");
        //日历插件
        $('#create_time_start').datetimepicker({"format":"YYYY-MM-DD HH:mm:ss","locale":"zh-CN"});
        $('#create_time_end').datetimepicker({"format":"YYYY-MM-DD HH:mm:ss","locale":"zh-CN","useCurrent":false});
        $("#create_time_start").on("dp.change", function (e) {
            $('#create_time_end').data("DateTimePicker").minDate(e.date);
        });
        $("#create_time_end").on("dp.change", function (e) {
            $('#create_time_start').data("DateTimePicker").maxDate(e.date);
        });

        //多选id数组
        var selectedRows = function () {
            var selected = [];
            $('.grid-row-checkbox:checked').each(function(){
                selected.push($(this).data('id'));
            });
            return selected;
        }



        //tr选中样式控制
        $('.grid-row-checkbox').iCheck({checkboxClass:'icheckbox_minimal-blue'}).on('ifChanged', function () {
            if (this.checked) {
                $(this).closest('tr').css('background-color', '#ffffd5');
            } else {
                $(this).closest('tr').css('background-color', '');
            }
        });





        //单条数据删除
        $('.grid-row-delete').unbind('click').click(function() {
            var id = $(this).data('id');
            console.log(id);
            swal({
                title: "确认删除?",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确认",
                showLoaderOnConfirm: true,
                cancelButtonText: "取消",
                preConfirm: function() {
                    return new Promise(function(resolve) {
                        $.ajax({
                            method: 'POST',
                            url: '/admin/goods/delete',
                            data: {
                                _method:'delete',
                                _token:LA.token,
                                goods_id:id
                            },
                            dataType:'json',
                            success: function (data) {
                                if(data.status==1){
                                    swal(data.message, '', 'success');
                                    $.pjax.reload('#pjax-container');
                                }else{
                                    swal(data.message, '', 'error');
                                }
                                resolve(data);
                            }
                        });
                    });
                }
            }).then(function(result) {
                var data = result.value;
                if (typeof data === 'object') {
                    if (data.status) {
                        swal(data.message, '', 'success');
                    } else {
                        swal(data.message, '', 'error');
                    }
                }
            });
        });


        //导出功能
        var selected_columns = ["goods_id","is_putaway","goods_name","keyword","goods_price","goods_official_price","goods_tenancy_term","create_time",""];
        $('.column-selector .dropdown-menu a').on('click', function(event) {
            var $target = $( event.currentTarget ),
                val = $target.attr('data-value'),
                $inp = $target.find('input'),
                idx;

            if ((idx = selected_columns.indexOf(val)) > -1) {
                selected_columns.splice(idx, 1);
                setTimeout(function() {$inp.prop('checked', false)}, 0);
            } else {
                selected_columns.push(val);
                setTimeout(function() {$inp.prop('checked', true)}, 0);
            }
            $(event.target).blur();
            return false;
        });

        //导出
        $('.column-select-submit').on('click', function () {
            if (selected_columns.length == 0) {
                return;
            }
            var url = new URL(location);
            // select all
            if ($('.column-selector .dropdown-menu a input').length == selected_columns.length) {
                url.searchParams.delete('_columns_');
            } else {
                url.searchParams.set('_columns_', selected_columns.join());
            }

            $.pjax({container:'#pjax-container', url: url.toString() });
        });

        //导出
        $('.column-select-all').on('click', function () {
            selected_columns = [];
            $('.column-selector .dropdown-menu a input').prop('checked', true);
            $('.column-selector .dropdown-menu a').each(function (_, val) {
                selected_columns.push($(val).data('value'));
            });

            return false;
        });


        //导出
        $('.export-selected').click(function (e) {
            e.preventDefault();

            var rows = selectedRows().join(',');
            if (!rows) {
                return false;
            }

            var href = $(this).attr('href').replace('__rows__', rows);
            location.href = href;
        });


        $('.grid-select-all').iCheck({checkboxClass:'icheckbox_minimal-blue'});

        $('.grid-select-all').on('ifChanged', function(event) {
            if (this.checked) {
                $('.grid-row-checkbox').iCheck('check');
            } else {
                $('.grid-row-checkbox').iCheck('uncheck');
            }
        });


        //多选处理
        $('.grid-batch-0').on('click', function() {
            var id = selectedRows().join();
            swal({
                title: "确认删除?",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确认",
                showLoaderOnConfirm: true,
                cancelButtonText: "取消",
                preConfirm: function() {
                    return new Promise(function(resolve) {
                        $.ajax({
                            method: 'post',
                            url: '/admin/goods/deal',
                            data: {
                                _token:LA.token,
                                id:id
                            },
                            success: function (data) {
                                $.pjax.reload('#pjax-container');

                                resolve(data);
                            }
                        });
                    });
                }
            }).then(function(result) {
                var data = result.value;
                if (typeof data === 'object') {
                    if (data.status) {
                        swal(data.message, '', 'success');
                    } else {
                        swal(data.message, '', 'error');
                    }
                }
            });
        });


        //刷新
        $('.grid-refresh').on('click', function() {
            $.pjax.reload('#pjax-container');
            toastr.success('刷新成功 !');
        });

        //搜索
        $('.shaixuan-filter-btn').unbind('click');
        $('.shaixuan-filter-btn').click(function (e) {
            if ($('#filter-box').is(':visible')) {
                $('#filter-box').addClass('hide');
            } else {
                $('#filter-box').removeClass('hide');
            }
        });
        @if($where)
        $('#filter-box').removeClass('hide');
        @endif



        $(".is_putaway").select2({
            placeholder: {"id":"","text":"\u9009\u62e9"},
            "allowClear":true
        });


        //改变分页量
        $('.grid-per-pager').on("change", function(e) {
            $.pjax({url: this.value, container: '#pjax-container'});
        });

        //分页
        $("a.page-link").click(function(e){
            var url=$(this).attr('data-href');
            $.pjax({url:url, container: '#pjax-container'});
        })
    });

    //删除或不删除
    function del(e,id){
        $.ajax({
            url:"/admin/goods/ajaxDel",
            data:{goods_id:id,_token:LA.token},
            type:'post',
            dataType:'json',
            success:function(m){
                if(m.status==1){
                    if(m.data.is_delete==1){
                        $(e).html('是').css("color",'red');
                    }else{
                        $(e).html('否').css("color",'blue');
                    }
                    toastr.success('ok');
                }else{
                    swal(m.message, '', 'error');
                }
            }
        });
    }

    function popShow(e){
        var url=$(e).attr('data-href');
        $("#popLayer").show();
        $("#popBox").show();
        $("#popFrame").attr('src',url);
        console.log(url);
    }
    function closeFrame(e) {
        $("#popBox").css('display','none');
        $("#popFrame").attr('src','');
        $('#popLayer').css('display','none');
    }
</script>